﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/FullSite.Master" Inherits="System.Web.Mvc.ViewPage<ToppingControl.Models.TopCordPlanModel.TopCordPlan_DS>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Topping Head Computer

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
   
    <%--   <link href='<%: Url.Content("~/Content/themes/base/jquery.ui.dialog.css")%>' rel="stylesheet" type="text/css" />--%>
<style type="text/css">
     
.btnF
{
font-size: 24px !important;
       
}
.hide
{
display: none;
}

.fontTB
{
font-size: 26pt !important;
}
#dTbl.rowa ,#dTbl.rowb, #dTbl1.rowa ,#dTbl1.rowb
{
   height: 60px!important;
}
#txtInput ,#TCLen ,#TCWd,#TWd ,#txtempnm,#txtpass,#txtshort
{
    font-size:38px;     
        
} /* Bigger text */
/***** KEY PAD*******/

    
   </style>
<div class="float-left"><h2>Topping Head Computer</h2></div>
<div class="float-right">
<div class="float-left"><h3>Topping NO. <%: Model._Topno %> </h3></div>
<div class="float-left" style="margin-left:25px;"><h3>Shift : <%: ViewBag.shift %></h3></div>
<div class="float-left" style="margin-left:25px;"><h3>Name : 
<% if (Request.IsAuthenticated)
   { %>
<%:  User.Identity.Name %></h3></div>
<% } %>
</div>



</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent2" runat="server">

    <div">
<br />
<% 
   string Itemno = "";
   if (WinNemoLib.StrUtil.IsNotEmpty( Model._Itemno)){
      Itemno = Model._Plandt + '-' + Model._Itemno;
      
   } %>
<table width="75%" style="height:80%" id="dTbl" >
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px; width:40%;">SEQ </td>
   <td class="cell" id="seqDT"><%= Itemno %> </td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Topped Cord</td>
   <td class="cell"><%= Model._Topcrdcd%> </td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Manufacturer</td>
   <td class="cell"><%= Model._Manufc %> </td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Length (M.)</td>
   <td class="cell"><%= Model._Length%> </td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord</td>
   <td class="cell" id="code"><%= Model._irccrdcd %> </td>
</tr>
<tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Confirm</td>
   <td class="cell"><input type="password" id="txtInput" style=" width:95% " /></td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Lot</td>
   <td class="cell" id="lot"></td>
</tr>
<tr class="rowb">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Expire</td>
   <td class="cell" id="exp"></td>
</tr>
<tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Tag Length (M.)</td>
   <td class="cell"><input type="text" id="TCLen" maxlength="4" /></td>
</tr>
<tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Tag Width (cm.)</td>
   <td class="cell"><input type="text" id="TCWd" maxlength="6" /></td>
</tr>
<tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">Tire Cord Width (cm.)</td>
   <td class="cell"><input type="text" id="TWd" maxlength="6" /></td>
</tr>
</table>
</div>
<input type="hidden" id="blnExp" value="" />

 <%--**************  Dialog ************--%>
<div id="dialog-a" title="Tire Cord is expired">

    <div class="cap cell" style="height:30px">Tire Cord</div>
    <div class="desc cell" id="dcode" ></div>
    <div style="clear:left"></div>
    <div class="cap cell"  style="height:30px">Tire Cord Lot</div>
    <div class="desc cell" id="dLot"></div>
    <div style="clear:left"></div>
    <div class="cap cell"  style="height:30px"> Tire Cord Expired</div>
    <div class="desc cell" id="dexp"></div>
</div>
<%--//************ dialog *******************//--%>
<div id="dialog-b" title="Use Tire Cord">
 <table style=" width:98%" class="dTbl">
   <tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px; width:30%">Emp code</td>
   <td class="cell"><input type="text" id="txtempnm" style=" width:75% " /></td>

</tr>
   <tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">Password</td>
   <td class="cell"><input type="password" id="txtpass" style=" width:75% " /></td>

</tr>
 <tr class="rowa">
   <td class="head cell text-right"  style="padding:10px 0px;">ShortText</td>
   <td class="cell"><input type="text" id="txtshort" style=" width:75% " /></td>

</tr>
       </table>
</div>

<div id="numericInput" style="float:left; width:300px;" >   
   <table id="keypad" class="hide">
         <tr style="background-color:#696969;"><td colspan="3" style="text-decoration:none; text-align:right;">
         <img src="<%: Url.Content("~/Images/power.png")%> "  alt='' width="100px" height="75px" id="close" />
         </td></tr>
         <tr class="rowa" >
            <td class="key">
               1
            </td>
            <td class="key ">
               2
            </td>
            <td class="key ">
               3
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               4
            </td>
            <td class="key ">
               5
            </td>
            <td class="key ">
               6
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               7
            </td>
            <td class="key ">
               8
            </td>
            <td class="key ">
               9
            </td>
         </tr>
         <tr class="rowa" >
            <td class="btn">
               DEL
            </td>
            <td class="key ">
               0
            </td>
            <td class="key ">
               .
            </td>
         </tr>
      </table>
</div>
</asp:Content>
<asp:Content ID="foot" ContentPlaceHolderID="TableContent" runat="server">
  


<div style="clear: left;  ">
     <div class="float-left" style="margin: 15px;">
         <input id="back" type="button" value="BACK" class="btnFooter shadow"  style="height: 75px; width: 350px;" />
      </div>
<div class="float-right" style="margin:15px;">
<input type="button" id="next" value="NEXT" class="btnFooter shadow" style="height: 75px; width: 350px;" />
</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">
    <% if (false) { %>
   <script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
   <% } %>
<script type="text/javascript">
    $(function () {
        $("#numericInput").draggable();
        var clickNum;
        $('.key').click(function (event) {

            var numBox = clickNum;
            o = numBox.data('mask');

            var max = o.maxLength;

            if (numBox.val().length == max) {
                return;
            }

            var v = $.trim(this.innerHTML);
            var valueArray = ($.trim(numBox.val())).split('')
            var idx = $.inArray(".", valueArray);

            if ((v == ".") && (idx > -1)) {
                return;
            }

            if ($.trim(this.innerHTML) == ".") {
                if ($.inArray(".", o.maskArray) < 0) {
                    return;
                }
                numBox.val(numBox.val() + '.');
                return;
            }

            var i = valueArray.length;


            if (idx >= 0) {
                var pt = o.maskArray.length - ($.inArray(".", o.maskArray));
                var x = valueArray.length + 1 - idx;
                if (x > pt) {
                    return;
                }
                i = $.inArray(".", o.maskArray) + 1;


            } else if ((i > 0) && (o.maskArray[i] == '.')) {
                numBox.val(numBox.val() + '.');
            }

            if (o.maskNonFixedCharsArray[i] == 'undefine') {
                return;
            }
            if (v <= o.maskNonFixedCharsArray[i]) {
                numBox.val(numBox.val() + v);
            }

            event.stopPropagation();
        });

        $('.btn,#close').click(function (event) {
            var numBox = clickNum
            if ($.trim(this.innerHTML) == 'DEL') {
                if (numBox.val().length > 0) {
                    clickNum.val(numBox.val().substring(0, numBox.val().length - 1));
                }
                else {
                    numBox.val('');
                }
            }
            else {
                $("#keypad").slideToggle();
                clickNum = null;
            }
            event.stopPropagation();
        });


        $('#TCLen,#TCWd,#TWd').click(function (event) {

            var o = {
                left: event.pageX + 100,
                top: event.pageY - 100
            };

            if ((clickNum == null) || ($(this).attr("id") == clickNum.attr("id"))) $("#keypad").slideToggle().offset(o);
            clickNum = $(this);
            event.stopPropagation();
        });

        $('#TCWd,#TWd').addClass("right").setMask("999.99").attr("maxlength", 6);
        $('#TCLen').addClass("right").setMask("9999").attr("maxlength", 4);



        $("#dialog-a").dialog({
            width: 600,
            height: 500,
            autoOpen: false,
            show: "blind",
            resizable: false, //สั่งให้ไม่สามารถย่อขยายได้
            modal: true,  //สั่งให้มีฉากเบลอๆด้านหลัง dialog
            open: function (event, ui) {
                $(this).parent().children(".ui-widget-header").css("background", "#B22222");
                $(this).parent().children(".ui-dialog-titlebar").css("color", "white");
                $("#txtempnm").val("");
                $("#txtpass").val("");
                $("#txtshort").val("");
            },
            buttons: {
                "Back": function () {
                    $(this).dialog("close");

                },
                "Use Tire Cord": function () {
                    $(this).dialog("close");

                    $("#dialog-b").dialog("open");
                }
            }
        });

        $("#dialog-b").dialog({
            width: 650,
            height: 400,
            autoOpen: false,
            show: "blind",
            buttons: {
                "Back": function () {
                    $(this).dialog("close");
                },
                "Back": function () {
                    $(this).dialog("close");
                },
                "OK": function () {
                    if ($("#txtempnm").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }
                    if ($("#txtpass").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }
                    if ($("#txtshort").val() == "") {
                        alert("ระบุข้อมูลไม่ครบ");
                        $("#TCLen").focus();
                        return;
                    }

                    $.post('<%=Url.Action("Get_Author","HeaderLine") %>' + '?users=' + $("#txtempnm").val() + '&pass=' + $("#txtpass").val()
               , function (data) {
                   if (data.success == 0) {
                       alert(data.message);
                   }
                   else {
                       $(this).dialog("close");
                       $("#blnExp").val("");
                       SaveData();
                   }
               });
                }
            }
        });

        if ($.trim($("#seqDT").text()) == "") {
            alert("ไม่พบข้อมูล");
            var url = '<%= Url.Action("Header_Line","HeaderLine") %>';
            window.location = url;
        }
        $('#txtInput').focus().change(function () {
            if (!GET_Barcode($(this).val())) {
                alert(" ข้อมูลไม่ถูกต้อง ");
                $('#txtInput').val("")
                $('#txtInput').focus();
            }
        });


        $("#next").click(function () {

            if ($("#txtInput").val() == "") {
                alert("ระบุข้อมูลไม่ครบ");
                $("#txtInput").focus();
                return;
            }
            if ($("#TCLen").val() == "") {
                alert("ระบุข้อมูลไม่ครบ");
                $("#TCLen").focus();
                return;
            }
            if ($("#TCWd").val() == "") {
                alert("ระบุข้อมูลไม่ครบ");
                $("#TCLen").focus();
                return;
            }
            if ($("#TWd").val() == "") {
                alert("ระบุข้อมูลไม่ครบ");
                $("#TCLen").focus();
                return;
            }
            if ($("#blnExp").val() == "") {
                $("#txtempnm").val("");
                $("#txtpass").val("");
                $("#txtshort").val("");
                SaveData();
            }
            else
                $("#dialog-a").dialog("open");
        });

        $("#back").click(function () {
            var url = '<%= Url.Action("RollBack","HeaderLine") %>' + '?seq=' + $.trim($("#seqDT").text())
            url = url + '&shift=' + '<%:  ViewBag.shift %>'
            window.location = url;
        });

        function GET_Barcode(barcode) {
            var myArray = barcode.split('+');
            $("#lot").text("");
            $("#exp").text("");

            if (myArray.length != 6) {

                return false;
            }
            if ($.trim('<%: Model._irccrdcd %>') == $.trim(myArray[0]).toString().toUpperCase()) {

                $("#blnExp").val("");
                $("#lot").text(myArray[1].toUpperCase());
                $("#dLot").text(myArray[1].toUpperCase());
                $("#dcode").text(myArray[0].toUpperCase());


                $.post('<%=Url.Action("ConvertDate","HeaderLine") %>' + '?sdate=' + myArray[4], function (data) {
                    if (data.sucess == 0) {
                        alert(data.message + '' + myArray[4]);
                        $("#txtInput").val("");
                        return false;
                    } else {
                        $("#exp").text(data.message);
                        $("#dexp").text(data.message);
                        $("#blnExp").val("");
                        if (!data.bln) {
                            $("#blnExp").val(data.bln);

                        }
                    }

                });
                return true;

            } else {
                //alert(($.trim($("#code").text())) );
                return false;
            }
        }

        function SaveData() {
            var dataForSubmit = new Array();
            var reason = "";
            if ($("#txtshort").val() != "") {
                reason = "Tire Cord is expired";
            }

            dataForSubmit.push({
                _Topno: '<%: Model._Topno %>',
                _Plandt: '<%: Model._Plandt %>',
                _Itemno: '<%: Model._Itemno %>',
                _Topcrdcd: '<%=Model._Topcrdcd %>',
                _Manufc: '<%: Model._Manufc %>',
                _Length: '<%: Model._Length %>',
                _Plants: '<%: Model._Plants %>',
                _UpTemp: '<%: Model._UpTemp %>',
                _Empname: '<%: User.Identity.Name %>',
                _Tcrdcd: $("#dcode").text().toUpperCase(),
                _Tcrdlot: $("#dLot").text().toUpperCase(),
                _Tcrdexp: $("#dexp").text(),
                _Tcrdtagl: $("#TCLen").val(),
                _Tcrdtagw: $("#TCWd").val(),
                _Tcrdw: $("#TWd").val(),
                _Tauthemp: $("#txtempnm").val().toUpperCase(),
                _Tshtxt: $("#txtshort").val(),
                _Treatxt: reason,
                _Shift: '<%:  ViewBag.shift %>'

            });

            var getUsersUrl = '<%= Url.Action("Save_Date","HeaderLine") %>';
            callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
        }
        /********* AJAX ********/

        function callScriptMethod(url, jsonObject, action, callback, async) {

            callback = callback || function () { };
            async = (async == null || async);

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: url,
                data: JSON.stringify(jsonObject),
                dataType: "json",
                async: async,
                success: function (data) {

                    if (data.success != "0") {
                        var getUsersUrl = '<%= Url.Action("Header_des_com","HeaderLine") %>' + '?seq=' + $.trim($("#seqDT").text());

                        window.location = getUsersUrl;
                    } else alert(data.message);
                },
                error: function (xhr, status, error) {
                    var err = xhr.responseText;
                    alert(err.Message);
                }
            });
        }
    });

       

</script>
</asp:Content>
